def extract_pokemon_names(input_file, output_file):
    # 读取文件内容
    with open(input_file, 'r', encoding='utf-8') as f:
        content = f.read().strip()

    # 分割所有字段
    tokens = content.split('+')

    # 存储序号和名称的映射字典
    pokemon_dict = {}

    # 遍历所有token，提取序号和名称
    for i in range(1, len(tokens)):
        token = tokens[i]
        # 检查是否是三位数字序号
        if token.isdigit() and len(token) == 3:
            prev_token = tokens[i-1]
            # 确保前一个token不是特殊标记"―"且不是数字
            if prev_token != '―' and not prev_token.isdigit():
                seq_num = token
                name = prev_token

                # 初始化该序号的列表（如果不存在）
                if seq_num not in pokemon_dict:
                    pokemon_dict[seq_num] = []

                # 避免重复添加相同名称
                if name not in pokemon_dict[seq_num]:
                    pokemon_dict[seq_num].append(name)

    # 准备输出列表
    result_names = []

    # 生成001到400的序号列表（补零到三位）
    all_seq_numbers = [str(num).zfill(3) for num in range(1, 401)]

    # 按顺序收集所有名称
    for seq in all_seq_numbers:
        if seq in pokemon_dict:
            result_names.extend(pokemon_dict[seq])

    # 将名称列表连接成字符串
    output_content = '+'.join(result_names)

    # 写入输出文件
    with open(output_file, 'w', encoding='utf-8') as f:
        f.write(output_content)

# 使用示例
extract_pokemon_names('pokedex.txt', 'pokemon_names.txt')